<template>
  <div>
    <el-table
      :data="tableData"
      style="width: 100%;margin-bottom: 20px;"
      row-key="id"
      border
      default-expand-all
      :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
    >
      <el-table-column
        prop="name"
        label="菜单名称"
      />
      <el-table-column
        prop="name"
        label="菜单名称"
      >
        <template v-slot="scope">
          <img :src="scope.row.icon" alt="">
        </template>
      </el-table-column>
      <el-table-column
        prop="sort"
        label="排序"
      />
    </el-table>
  </div>
</template>

<script>
import {
  getAllCategory
} from '@/api/goodsManage/category'
export default {
  data() {
    return {
      tableData: []
    }
  },
  computed: {

  },
  created() {
    getAllCategory()
      .then(res => {
        var arr = res.data.items.find(ele => ele.category.name == '乐居').children
        var newArr = res.data.items.map(ele => {
          var obj = {
            ...ele.category,
            children: ele.children
          }
          return obj
        })
        console.log(newArr)
        this.tableData = newArr
      })
  },
  mounted() {

  },
  methods: {

  }
}
</script>

<style scoped lang="scss">

</style>
